<?php

namespace app\admin\controller;

use app\admin\service\DriverService;

class DriverController extends CommonController
{
    // 获取司机数据
    public function getDriverAll(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(DriverService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getAll();
        return $this->return_result($this->returnData);
    }

    // 获取司机数据的分页列表
    public function getDriverList(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(DriverService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getList();
        return $this->return_result($this->returnData);
    }

    // 添加司机
    public function toAddDriver(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(DriverService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toAdd();
        return $this->return_result($this->returnData);
    }

    // 更新司机
    public function toUpdateDriver(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(DriverService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toUpdate();
        return $this->return_result($this->returnData);
    }

    // 通过模板文件导入数据
    public function toImportData(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(DriverService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toImportByExcel();
        return $this->return_result($this->returnData);
    }

    // 下载导入模板文件
    public function getImportTemplate(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(DriverService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toExportByExcel();
        return $this->return_result($this->returnData);
    }

    // 更新司机上下线状态
    public function toUpdateStatus(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(DriverService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toUpdateStatus();
        return $this->return_result($this->returnData);
    }

    // 司机的详细内容
    public function getDriverDetail(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(DriverService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->getDetail();
        return $this->return_result($this->returnData);
    }

    // 删除司机
    public function toDelDriver(){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $service = $this->app->invokeClass(DriverService::class, [$this->returnData, $this->params]);
        $this->returnData = $service->toDel();
        return $this->return_result($this->returnData);
    }

}